﻿@model CmsAdminPageModel

@{
    Layout = "~/admin/Templates/TelerikAdministration.cshtml";

    ResFile = "cms_Pages";
    
    int currentTemplateRegion = ViewBag.CurrentTemplateRegion;
    if (currentTemplateRegion == 0)
    {
        currentTemplateRegion = int.Parse(Model.TemplateRegionList.Select(p => p.Value).First());
    }    
}

@functions{
    MvcHtmlString RenderEditableBlock(Func<CmsAdminPageModel, object> editemplate, Func<CmsAdminPageModel, object> viewTemplate, bool hasMaskedFields = false, string additionalClass = "")
    {
        TagBuilder builder = new TagBuilder("li");

        builder.AddCssClass("b-form__row");
        builder.AddCssClass("g-clear");
        builder.AddCssClass(additionalClass);
        
        if(hasMaskedFields)
        {
            builder.AddCssClass("b-form__row_masked");
        }

        builder.InnerHtml = Model.IsLatestRevision ?
            editemplate(Model).ToString() :
            viewTemplate(Model).ToString();

        return MvcHtmlString.Create(builder.ToString(TagRenderMode.Normal));
    }
}

@RenderSection("DescriptionBlock")

@{Html.RenderPartial("ErrorPanel");}
@using (Html.BeginForm("edit", "cmspage", FormMethod.Post, new { id = "pageEdit" }))
{
<div class="primary-content">
    <fieldset class="b-form b-form_nopad">
        <ol class="b-form__rows ul-reset g-clear">
            @RenderEditableBlock(
                @<text>
                    <label for="PageName">@_("Page Title")</label>
                    @Html.TextBoxFor(p => p.PageName, new { @class = "text" })
                    @Html.ValidationMessageFor(p => p.PageName)
                    <a class="js-title-override-link" href="#">
                        <i class="b-icon"></i>
                        @_("Add Title override")
                    </a>
                    &nbsp;
                    @Html.Partial("tooltip",
                        new { Title = _("Page title"), Body = _("The title of your page will display in your website navigation. The <b>title override</b> function enables you to specify a different header on the actual page.") }.ToExpando())
                </text>,
                @<text>
                    <label for="PageName">@_("Page Title")</label>
                    @Html.TextBoxFor(p => p.PageName, new { @class = "text", disabled = "disabled" })
                </text>)
            @RenderEditableBlock(
             @<text>            
                  <label for="PageTitle">@_("Title override")</label>
                    @Html.TextBoxFor(p => p.PageTitle, new { @class = "text" })
                    @Html.ValidationMessageFor(p => p.PageTitle)
              </text>,
             @<text>            
                    <label for="PageTitle">@_("Title override")</label>
                    @Html.TextBoxFor(p => p.PageTitle, new { @class = "text", disabled = "disabled" })
                    @Html.ValidationMessageFor(p => p.PageTitle)
              </text>          
            , false, "js-title-override " + (Model.PageTitle == null ? "hide" : ""))

            @RenderEditableBlock(
                @<text>
                    <label for="PageUrl">@_("Page url")</label>
                    @Html.TextBoxFor(p => p.PageUrl, new { @class = "text" })
                    <div class="b-text-mask b-text-mask-page-url"></div>
                    <button id="pageUrl-edit" type="button" class="b-button b-button_small">@_("Edit")</button>
                    <button id="pageUrl-cancel" type="button" class="b-button b-button_small b-button_colour_grey hide">@_("Cancel")</button>
                    @Html.ValidationMessageFor(p => p.PageUrl)                    
                </text>,
                @<text>
                    <label for="PageUrl">@_("Page url")</label>
                    @Html.TextBoxFor(p => p.PageUrl, new { @class = "text", disabled = "disabled" })
                 </text>, true)                        

            <li class="b-form__row g-clear js-page-type js-redirect">
                    <label for="RedirectType">@_("Redirect type")</label>
                    @Html.DropDownListFor(p => p.RedirectType, new SelectList(Model.RedirectTypes, "Value", "Text"))
                </li>                
                <li class="b-form__row g-clear js-page-type js-redirect">
                    <label for="RedirectUrl">@_("Redirect Url")</label>
                    @Html.TextBoxFor(p => p.RedirectUrl, new { @class = "text" })
                    @Html.ValidationMessageFor(p => p.RedirectUrl)
                </li>
                <li class="b-form__row g-clear js-page-type js-redirect">
                or
                </li>
                <li class="b-form__row g-clear b-form__row_masked js-page-type js-redirect">
                    <label for="PageName">@_("Redirect to page")</label>
                    @Html.TextBoxFor(p => p.RedirectPageName, new { @class = "text" })
                    @Html.HiddenFor(p => p.RedirectPageId, new { @class = "text rel-property" })                    
                    @{Html.RenderPartial("FileViewDialog", new CmsFileViewModel { DialogFor = "Page", TargetId = "RedirectPageName, RedirectPageId" });}
        	        <div class="b-text-mask"></div>
                </li>
                <li class="b-form__row g-clear js-page-type js-redirect">
                    <label for="RedirectOpenInNewWindow">@_("Open in new window")</label>
                    @Html.CheckBoxFor(p => p.RedirectOpenInNewWindow)            
                </li>                 
            @RenderSection("AdditionalPageProperties", false)
        </ol>
    </fieldset>
<div class="b-form b-form_bordered b-form_theme_white js-page-type js-content">
    <div class="b-form__head"></div>
    <div class="b-form__body">
		<fieldset class="b-form b-form_nopad b-form_wrapped">
			<ol class="b-form__rows ul-reset g-clear">
			    <li class="b-form__row g-clear">
	                <label for="TemplateRegionList">@_("Select page region")</label>
	                @Html.DropDownList("Value", new SelectList(Model.TemplateRegionList, "Value", "Text", currentTemplateRegion), new { id = "TemplateRegionList", @class = "reset-me" })
	                <input type="hidden" name="Id" value="@Model.Id" />    
	                <a class="template-preview" href="@Url.Action("showregions", "cmstemplate", new { id = Model.TemplateId })">@_("Show regions")</a>            
	            </li>
			</ol>
		</fieldset>
	    <div id="pageControls">
	        @{Html.RenderAction("pagecontrols", new { pageId = Model.Id, templateRegionId = currentTemplateRegion, editable = Model.IsLatestRevision });}
	    </div>
	    @if (Model.IsLatestRevision)
     {
	    <div id="availablePageControls">
	        @{Html.RenderPartial("availablePageControls", new { PageId = Model.Id, CurrentTemplateRegion = currentTemplateRegion }.ToExpando());}
	    </div>
                 
     }
    </div>
</div>
    <div id="seoProperties" class="js-page-type js-content">
        <div class="b-form b-form_bordered b-form_theme_white">
	        <div class="b-form__head g-clear">
		        <h3 class="b-form__title">@_("Search engine information") @{Html.RenderPartial("tooltip", new { Title = "", Body = _("SEO") }.ToExpando()); }</h3>                
	        </div>
	        <div class="b-form__body">
                <fieldset class="b-form">
                    <ol class="b-form__rows ul-reset g-clear">
                        @RenderEditableBlock(
                        @<text>
                            <label for="PageDescription">@_("Meta description")</label>
                            @Html.TextAreaFor(p => p.PageDescription, new { @class = "text" })
                            @Html.ValidationMessageFor(p => p.PageDescription)
                        </text>,
                        @<text>
                            <label for="PageDescription">@_("Meta description")</label>                           
                            @Html.TextAreaFor(p => p.PageDescription, new { @class = "text", disabled = "disabled" })
                        </text>)
                        @RenderEditableBlock(
                        @<text>
                            <label for="PageKeywords">@_("Meta keywords")</label>
                            @Html.TextAreaFor(p => p.PageKeywords, new { @class = "text" })
                            @Html.ValidationMessageFor(p => p.PageKeywords)
                        </text>,
                        @<text>
                            <label for="PageKeywords">@_("Meta keywords")</label>                           
                            @Html.TextAreaFor(p => p.PageKeywords, new { @class = "text", disabled = "disabled" })
                        </text>)
                    </ol>
                </fieldset>
	        </div>
	    </div>
    </div>
    
    <div class="js-page-type js-placeholder js-redirect">
        <strong>@_("This page does not support regions")</strong>
    </div>

    @RenderSection("AdditionalPropertiesBlock", false)  
    @if (CmsConfiguration.IsWorkflowEnabled)
    { 
        <div class="hide">
            @{Html.RenderAction("SendForApproval", Model.Id);}
        </div>
    }
</div>
    <div class="secondary-content">
        @RenderSection("ButtonsBlock", true)    
        <div class="b-form b-form_narrow b-form_bordered b-form_theme_white">
            <div class="b-form__head">
                <h3 class="b-form__title">@_("Page attributes")</h3>
            </div>
            <div class="b-form__body">
                <ol class="b-form__rows ul-reset g-clear">
                    @Html.HiddenFor(p => p.PublicPageId)
                    @RenderEditableBlock(
                        @<text>
                            @_("Public page id:") @Model.PublicPageId
                        </text>,
                        @<text>
                             Public page id: @Model.PublicPageId
                        </text>
                        )                
                    @RenderEditableBlock(
                        @<text>
                             @Html.CheckBoxFor(p => p.IsVisible)
                             <label for="IsVisible">@_("Visible on navigation bar")</label>
                         </text>,
                        @<text>
                             @Html.CheckBoxFor(p => p.IsVisible, new { disabled = "disabled" })
                             <label for="IsVisible">@_("Visible on navigation bar")</label>
                         </text>)
                    @if (!CmsConfiguration.IsWorkflowEnabled)
                    {
                        @RenderEditableBlock(
                            @<text>
                                 @Html.CheckBoxFor(p => p.IsPublished)
                                 <label for="IsPublished">@_("Published")</label>
                             </text>,
                            @<text>
                                 @Html.CheckBoxFor(p => p.IsPublished, new {disabled="disabled"})
                                 <label for="IsPublished">@_("Published")</label>
                             </text>)
                        @RenderEditableBlock(
                            @<text>
                    
                                 <label for="PublishStartDate">@_("Publish from")</label>
                                 @(Html.Telerik().DatePicker()
                                       .Name("PublishStartDate")
                                       .InputHtmlAttributes(new { @class = "text b-text_date" })
                                       .ShowButton(true))
                             </text>,
                            @<text>
                                 @_("Publish from"): @Model.PublishStartDate
                             </text>
                            )
                        @RenderEditableBlock(
                            @<text>                    
                                 <label for="PublishEndDate">@_("Publish to")</label>
                                 @(Html.Telerik().DatePicker()
                                       .Name("PublishEndDate")
                                       .InputHtmlAttributes(new { @class = "text b-text_date" })
                                       .ShowButton(true))
                             </text>,
                            @<text>
                                 @_("Publish to"): @Model.PublishEndDate
                             </text>
                            )
                    }
                    @if (Model.ParentPageId.HasValue)
                    {
                        <li class="b-form__row g-clear b-form__row_masked">                            
                            <label for="ParentPageId">@_("Parent page")</label>
                            @Html.TextBoxFor(p => p.ParentPageName, new { @class = "text" })
                            @Html.HiddenFor(p => p.ParentPageId, new { @class = "text rel-property" })                    
                            @if (Model.IsLatestRevision)
                            {
                                Html.RenderPartial("FileViewDialog", new CmsFileViewModel{ DialogFor = "Page", TargetId = "ParentPageName, ParentPageId", CurrentPageId = Model.Id });
                            }                
                            <div class="b-text-mask"></div>
                        </li> 
                    }
                    @RenderEditableBlock(
                        @<text>
                             <label>@_("Order location")</label>
                             @Html.Partial("PageLocation", new { Page = Model.ConvertToPage(), ClientId = "PageLocation", Disabled = false }.ToExpando())
                         </text>,
                        @<text>
                    
                         </text>)
                    @RenderEditableBlock(
                        @<text>
                             <label for="PageTypeKey">@_("Page type")</label>
                             @Html.DropDownListFor(p => p.BehaviourPageType, Model.PageTypeList, new { @class = "js-select-show-hide", data_container = ".js-page-type" })
                         </text>,
                        @<text>
                             <label for="PageTypeKey">@_("Page type")</label>
                             @Html.DropDownListFor(p => p.BehaviourPageType, Model.PageTypeList, new { @class = "js-select-show-hide", data_container = ".js-page-type", disabled = "disabled" })
                         </text>)
                    @RenderEditableBlock(
                        @<text>
                             <label for="TemplateId">@_("Template")</label>
                             @Html.DropDownListFor(p => p.TemplateId, new SelectList(Model.TemplateList, "Value", "Text", Model.TemplateId))
                         </text>,
                        @<text>
                             <label for="TemplateId">@_("Template")</label>
                             @Html.DropDownListFor(p => p.TemplateId, new SelectList(Model.TemplateList, "Value", "Text", Model.TemplateId), new { disabled = "disabled" })
                         </text>, false, "js-page-type js-content")            
                    @(Html.UserGroupPlaceholder().ForUserGroups(PredefinedUserGroups.Developer).Template(
                          @<text>
                               <li class="b-form__row g-clear">
                                   @Html.CheckBoxFor(p => p.UseFileCache)
                                   <label for="UseFileCache">@_("Use file cache")</label>
                               </li>
                           </text>).Render())
                    @RenderEditableBlock(
                        @<text>
                            <label for="PageKey">@_("Page key")</label>
                            @Html.TextBoxFor(m=>m.PageKey, new {@class = "text"})
                        
                        </text>,
                        @<text>
                             @_("Page key"): @Model.PageKey
                        </text>
                        ) 
                    
                </ol>                   
            </div>
        </div>
        @if (Model.IsLatestRevision)
        {
            <div class="b-form b-form_narrow b-form_bordered b-form_theme_white">
                <div class="b-form__head">
                    <h3 class="b-form__title">@_("Workflow notes & page history")</h3>
                </div>
                <div class="b-form__body">
                    <ol class="b-form__rows ul-reset g-clear">                
                        <li class="b-form__row g-clear">
                            <p>@_("View all notes and historical changes relating to this page and content")</p>
                        </li>
                        <li class="b-form__row g-clear">
                            <a class="b-button b-button_small" href="@Url.Action("pagehistory", "cmspage", new { id = Model.Id })">@_("View workflow notes")</a>
                        </li>                      
                    </ol>                   
                </div>
            </div>
        }
    
        <div class="b-form b-form_narrow b-form_bordered b-form_theme_white">
            <div class="b-form__head">
                <h3 class="b-form__title">@_("Custom Properties")</h3>
            </div>
            <div class="b-form__body">
                @Html.Action("EntityMetaValues", "CmsMetaField", new { metaInformation = Model.MetaInformation, isValid = @ViewData.ModelState.IsValid})
            </div>
        </div>
    </div>
    @Html.HiddenFor(m=>m.IsSaveConfirmation)
}

<div id="tmp" class="hide">
    <iframe id="previewIfr" src="javascript:'<html></html>';" scrolling="no"></iframe>
</div>

<script type="text/javascript">
    $(function () {
        $('.js-submit-page-edit').live('click', function (e) {
            e.preventDefault();
            $('#IsSaveConfirmation').val(true);
            $('#pageEdit').submit();
        });

        setHoverDeleteSectionForControls($('.js-control-head'));
    });
</script>
